<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'"
             :close-on-click-modal="false"
             :visible.sync="visible">
    <el-form :model="dataForm"
             :rules="dataRule"
             ref="dataForm"
             @keyup.enter.native="dataFormSubmit()"
             label-width="80px">
      
	  <el-form-item label="商城" prop="mallid" :rules="[{ required: true, message: '请选择商城'}]">
        <el-col :span="8">
          <el-select v-model="dataForm.mallid"
                    
                    style="width: 250px"
                    placeholder="请选择">
			
            <el-option  v-for="item in this.malls"
                      :key="item.id"
                      :label="item.mallName"
                      :value="item.id">
            </el-option>
			
          </el-select>
        </el-col>
      </el-form-item>
      
	  
	  <el-form-item label="手机号"
                    prop="mobile":rules="[
                      { required: true, pattern: /\s\S+|S+\s|\S/, message: '请输入手机号', trigger: 'blur' }
                    ]">
        <el-col :span="16">
          <el-input-number v-model="dataForm.mobile"
                    placeholder="手机号" style="width: 230px"></el-input-number>
        </el-col>
      </el-form-item>
	  <el-form-item label="积分"
                    prop="balance":rules="[
                      { required: true, pattern: /\s\S+|S+\s|\S/, message: '请输入积分', trigger: 'blur' }
                    ]">
        <el-col :span="8">
          <el-input-number v-model="dataForm.balance"
                    placeholder="请输入积分"></el-input-number>
        </el-col>
      </el-form-item>
	  <el-form-item label="姓名"
                    prop="userName":rules="[
                      { required: false, pattern: /\s\S+|S+\s|\S/, message: '请输入姓名', trigger: 'blur' }
                    ]">
        <el-col :span="8">
          <el-input v-model="dataForm.userName"
                    placeholder="请输入姓名"></el-input>
        </el-col>
      </el-form-item>
    </el-form>
    <span slot="footer"
          class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary"
                 @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { Debounce } from '@/utils/debounce'
export default {
  data () {
    return {
      visible: false,
      roleList: [],
      dataForm: {
        id: null,
		mobile: null,
		balance: 0,
		mallid: null,
		malls: [],
        userName: null,
        shopId: null,
        status: 1,
        isDefault: null,
        prodCount: null,
        seq: null,
        style: 0
      },
      dataRule: {
      }
    }
  },
  methods: {
    init (id) {
	
	  //console.log(this.malls,this.$malls)
	  this.malls=this.malls=this.$myGlobalData.mallsList.slice(1)
	  //console.log(this.malls,this.$malls)
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl('/prod/phone/info/' + this.dataForm.id),
            method: 'get',
            params: this.$http.adornParams()
          }).then(({ data }) => {
            this.dataForm = data
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit: Debounce(function () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/prod/phone'),
            method: this.dataForm.id ? 'put' : 'post',
            data: this.$http.adornData(this.dataForm)
          }).then(({ data }) => {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          })
        }
      })
    })
  }
}
</script>
